// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Shader from "../../Shader";



const { ccclass, property } = cc._decorator;

@ccclass
export default class RadialBlurShader extends Shader {
    @property
    _blurRadius: number = 1;

    @property
    get blurRadius() {
        return this._blurRadius;
    }

    set blurRadius(value) {
        this._blurRadius = value;
        this.updateBlurRadius();
    }

    protected start(): void {
        this.updateBlurRadius();
        this.updatePixelSize();
    }

    private updateBlurRadius() {
        this.material.setProperty("u_blurRadius", this._blurRadius);
    }

    private updatePixelSize() {
        this.material.setProperty("u_pixelSize", cc.v2(1 / this.node.width, 1 / this.node.height));
    }
}
